<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <title>开源中国</title>
    <script type="text/javascript" src="./script/api.js"></script>
    <script type="text/javascript" src="./script/zepto.min.js"></script>
    <script type="text/javascript" src="./script/config.js"></script>
    <script type="text/javascript" src="./script/common.js"></script>
    <style>
        html {
            height: 100%;
            background-color: #FFFFFF;
        }

        body {
            background-color: #fff;
            padding: 0;
            margin: 0;
            display: -webkit-box;
            display: -webkit-flex;
            display: flex;
            height: 100%;
            -webkit-box-orient: vertical;
            -webkit-flex-flow: column;
            flex-flow: column;
        }
    </style>
</head>
<body>
<script>
	var client_id, client_secret, redirect_uri;
	
    apiready = function () {

        if($api.getStorage('access_token')) {
            api.openSlidLayout({
                type: 'left',
                leftEdge: api.winWidth / 3,
                fixedPane: {
                    name: 'home_fixed',
                    url: './html/home_fixed.html'
                },
                slidPane: {
                    name: 'home_slide',
                    url: './html/home_slide.html'
                }
            }, function (ret) {

            });
        }else{
			api.openFrame({
			    name: 'login',
			    url: './html/frm_login.html',
			    rect:{
			        x:0,
			        y:0,
			        w:'auto',
			        h:'auto'
			    },
			    bounces: false,
			    opaque: false,
			    vScrollBarEnabled:false,
			    hScrollBarEnabled:false
			});

        }
        
       
    }
    
    
    // 刷新 access_token
    function refreshToken(){
    log(client_id+' '+client_secret+' '+$api.getStorage('refresh_token'));
		api.ajax({
			url: OpenAPI.access_token,
			method: 'post',
			timeout: 30,
			dataType: 'json',
			data:{
				values: {
					client_id: client_id,
					client_secret: client_secret,
					grant_type: 'refresh_token',
					redirect_uri: redirect_uri,
					refresh_token:$api.getStorage('refresh_token'),
					dataType:OpenAPI.dataType,
					callback:'json',
				},
			},
			returnAll:false,
		},function(ret,err){
		    if (ret) {
		    	$api.setStorage('access_token',ret.access_token);
		    	$api.setStorage('refresh_token',ret.refresh_token);
		    	$api.setStorage('token_type',ret.token_type);
		    	$api.setStorage('expires_in',ret.expires_in);
		    	$api.setStorage('uid',ret.uid);
		    	log('刷新 access_token成功');
		    }else {
		    	log('错误码：'+err.code+'；错误信息：'+err.msg+'网络状态码：'+err.statusCode);
		    	/*
		    	$api.rmStorage('access_token');
		    	$api.rmStorage('refresh_token');
		    	$api.rmStorage('token_type');
		    	$api.rmStorage('expires_in');
		    	$api.rmStorage('uid');
		    	*/
		    };
		});
		
    }
</script>
</body>
</html>